package com.hoongs.v1.vo;

import cn.hutool.core.bean.BeanUtil;
import com.hoongs.v1.entity.Cart;
import com.hoongs.v1.entity.OrderProduct;
import com.hoongs.v1.entity.Product;
import lombok.Data;
import java.math.BigDecimal;

@Data
public class ProductVo {

    private String id;

    private String orderId;         // 所属订单ID
    private String cartId;         // 所属购物车ID

    private String image;
    private String imageThumb;

    private String name;

    private BigDecimal price;         // 商品价格

    private BigDecimal originalPrice;         // 商品原价（未优惠价格）

    private BigDecimal number = null;         // 商品数量

    private String size;         // 商品规格
    private String sizeDictValue = "";

    private String type;          //  商品类型 1:普通商品 2:套餐 3:小料

    private String cateId;      // 商品分类id

    private String cateName;      // 商品分类名称

    private String summary;         // 商品简介

    private String remark;         // 商品备注


    public static ProductVo voFromCartDao(Product product, Cart cart){
        ProductVo productVo = BeanUtil.copyProperties(product, ProductVo.class);
        productVo.setNumber(cart.getNumber());
        productVo.setCartId(cart.getId());
        return productVo;
    }

    /**
     * OrderProduct 和 Product 组合成 ProductVo
     * @param product
     * @param orderProduct
     * @return
     */
    public static ProductVo voFromOPDao(Product product, OrderProduct orderProduct){
        ProductVo productVo = BeanUtil.copyProperties(product, ProductVo.class);
        productVo.setPrice(orderProduct.getPrice());
        productVo.setNumber(orderProduct.getNumber());
        productVo.setOrderId(orderProduct.getOrderId());
        return productVo;
    }

    public static Product voToDao(ProductVo productVo){
        Product product = BeanUtil.copyProperties(productVo, Product.class);
        return product;
    }
}
